﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace chapter4_thread_3
{

    public class WindowHelper
    {
        public static void ShowTime(object userData)
        {
            int oldX = Console.CursorLeft;
            int oldY = Console.CursorTop;

            Console.SetCursorPosition(0, 0);
            Console.Write(DateTime.Now.ToLongTimeString());

            Console.CursorLeft = oldX;
            Console.CursorTop = oldY;
        }
    }

    public class ThreadDemo
    {
        public void HelloWorld()
        {
            Console.WriteLine("Hello, world.");
        }

        public void RepeatHelloWorld(object count)
        {
            for (int i = 0; i < (int)count; i++)
            {
                Console.WriteLine("Repeat Hello, world.");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            System.Threading.Timer clock = new Timer(WindowHelper.ShowTime, null, 0, 1000);

            ThreadDemo demo = new ThreadDemo();

            Thread threadNoParameter = new Thread(demo.HelloWorld);
            threadNoParameter.Start();

            Thread threadWithParameter = new Thread(demo.RepeatHelloWorld);
            threadWithParameter.Start(5);

            Console.ReadLine();
        }
    }
}
